<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>Layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}">
    <script th:src="@{/layui/layui.js}"></script>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">客户名称</label>
        <div class="layui-input-block">
            <input type="text" name="cusName" lay-verify="required" autocomplete="off" placeholder="请输入客户名称"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户区域</label>
        <div class="layui-input-block">
            <select name="cusRegion" lay-verify="required">
                <option value="请选择"></option>
                <option value="1">东北</option>
                <option value="2">西北</option>
                <option value="3">华北</option>
                <option value="4">华东</option>
                <option value="5">华中</option>
                <option value="6">华南</option>
                <option value="7">西南</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户网址</label>
        <div class="layui-input-block">
            <input type="text" name="cusUrl" autocomplete="off" placeholder="请输入客户网址" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">客户等级</label>
        <div class="layui-input-block">
            <select name="cusLevel" lay-verify="required" >
                <option value="请选择"></option>
                <option value="1">战略合作伙伴</option>
                <option value="2">VIP客户</option>
                <option value="3">大客户</option>
                <option value="4">普通客户</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">信用等级</label>
        <div class="layui-input-block">
            <select name="cusCredit" lay-verify="required" >
                <option value="请选择"></option>
                <option value="1">信用极好</option>
                <option value="2">信用较好</option>
                <option value="3">信用一般</option>
                <option value="4">信用欠佳</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>

</form>


<script>
    layui.use(['form', 'jquery'], function () {
        var form = layui.form
        var $ =  layui.jquery
        //监听提交
        form.on('submit(demo1)', function (data) {
            console.log(data);
            if (form.verify()){
                $.ajax({
                     url:"/customer/save"//规定异步提交的路径
                    ,type:"POST"//规定提交的方式:POST.GET
                    ,data:data.field//提交给后台的数据
                    ,dataType:"json"//规定后台返回给浏览器的数据格式
                    ,success:function (d) {
                        layer.msg(d.msg,{shift:-1},function () {
                            parent.table.reload("test")
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        })
                    }
                })
            }

            return false;//防止form提交刷新
        });

        //表单取值
        layui.$('#LAY-component-form-getval').on('click', function () {
            var data = form.val('example');
            alert(JSON.stringify(data));
        });

    });
</script>

</body>
</html>